/*
 * @Author: xuhongling
 * @Date:   2023-08-24 14:51:00
 * @Last Modified by:   xuhongling
 * @Last Modified time: 2024-07-09 21:59:03
 */
import dateTimeLabelFormat from '@/hooks/web/useDateTimeFormat';

// ECharts Option
const setChartOption = (stationData, chartData) => {
  const timeData: any = [];
  const currentRainData: any = [];
  const rain_5minuteData: any = [];
  for (let i = 0; i < chartData.length; i++) {
    timeData.push(chartData[i].tm)
    currentRainData.push(chartData[i].currentRainVal)
    rain_5minuteData.push(chartData[i].rain_5minuteVal)
  }

  const chartOption:any = {
    color: ['#12c277', '#298def', '#91cc75'],
    title: {
      text: `${stationData.stnm}站雨量统计`,
      left: 'center',
      top: '10',
      textStyle: {
        fontSize: 16,
      },
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      left: "center",
      top: "44",
      itemWidth: 20,
      data: ['当前降雨量', '五分钟降水量'],
    },
    xAxis: {
      type: 'category',
      boundaryGap: true,
      data: timeData,
      axisLine: {
        onZero: false,
        lineStyle: {
          type: 'solid',
          color: '#333'
        }
      },
      axisTick: {
        show: true,
        inside: true,
        interval: 'auto',
        lineStyle: {
          color: '#999'
        }
      },
      axisLabel: {
        show: true,
        margin: 14,
        textStyle: {
          color: "#333",
          fontSize: 12,
        },
        formatter: (value, index) => {
          return dateTimeLabelFormat(value, index)
        }
      },
    },
    yAxis: [
      {
        type: 'value',
        position: 'left',
        name: '降雨量(mm)',
        yAxisIndex: 0,
        scale: true,
        splitNumber: 5,
        boundaryGap: ['0', '5%'],
        nameTextStyle: {
          color: '#333'
        },
        axisTick: {
          show: false,
        },
        axisLine: {
          show: true,
          lineStyle: {
            color: '#333'
          }
        },
        axisLabel: {
          show: true,
          textStyle: {
            color: "#333",
            fontSize: 12,
          }
        },
        splitLine: {
          show: true,
          lineStyle: {
            type: 'dashed',
            color: '#f4f4f4'
          }
        },
      },
    ],
    series: [
      {
        name: '当前降雨量',
        type: 'bar',
        yAxisIndex: 0,
        barMaxWidth: 10, //柱图宽度
        itemStyle: {
          color: '#12c277',
        },
        data: currentRainData,
      },
      {
        name: '五分钟降水量',
        type: 'bar',
        yAxisIndex: 0,
        barMaxWidth: 10, //柱图宽度
        itemStyle: {
          color: '#62adff',
        },
        data: rain_5minuteData,
      },
    ],
  }
  return chartOption
}

export default setChartOption;
